﻿<!DOCTYPE html>

<html>

<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    @Scripts.Render("~/Resource/js/fe.head.js")
</head>

<body>
    <div id="app" v-cloak>
        <el-container class="list_pagecontainer">
            <el-aside width="200px">
                <div>
                    <common-tree :tree-data="treeData" :tree-body-height="treeHeight" v-on:tree-node-click="nodeClick">
                    </common-tree>
                </div>
            </el-aside>
            <el-main>
                <el-container class="list_pagecontainer">
                    <el-header>
                        <el-row>
                            <el-col :span="24">
                                <div class="list_searchcontainer">
                                    <el-input placeholder="请输入模块名称" v-model="moduleName" class="list_searchinput">
                                    </el-input>
                                    <el-checkbox v-model="SearchInAll">所有模块</el-checkbox>
                                    <el-button type="primary" v-on:click="bindGrid" icon="el-icon-search">搜索</el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </el-header>
                    <el-main>
                        <common-table :data="tableData" :page-Index="pageIndex" :page-Size="pageSize" :total="total"
                            :table-Height="tableHeight" :show-Delete="false" v-on:on-load="bindGrid" v-on:on-pageindexchange="pageIndexChange"
                            v-on:handle-edit="edit" ref="table" v-on:on-pageindexchange="pageIndexChange">
                            <template slot="column">
                                <el-table-column prop="ModuleName" header-align="center" align="left" label="菜单名称">
                                </el-table-column>
                                <el-table-column prop="ModuleUrl" header-align="center" align="left" label="菜单地址">
                                </el-table-column>
                                <el-table-column prop="ModuleCode" header-align="center" align="left" label="菜单编码"
                                    width="280">
                                </el-table-column>
                                <el-table-column prop="OrderNum" header-align="center" align="center" label="排序"
                                    width="100">
                                </el-table-column>
                            </template>
                        </common-table>
                    </el-main>
                    <el-footer>
                        <el-row>
                            <el-col :span="24">
                                <div class="list_opcontainer">
                                    <el-button type="primary" v-on:click="add">添加模块</el-button>
                                    <el-button type="danger" v-on:click="batchDelete">删除选中</el-button>
                                </div>
                            </el-col>
                        </el-row>
                    </el-footer>
                </el-container>
            </el-main>
        </el-container>
    </div>
</body>
@Scripts.Render("~/Resource/js/fe.foot.js")
@Scripts.Render("~/Resource/component/tree/index.js")

</html>

<script>
    var treeUrl = GetRootPath() + "Frame/Module/Tree"
    var tableUrl = GetRootPath() + "Frame/Module/FindList"
    var batchDeletetUrl = GetRootPath() + "Frame/Module/OperateBatchDelete"
    var pageData = {
        //data
        tableData: [],
        treeData: [],
        //page
        pageIndex: 1,
        pageSize: 10,
        total: 0,
        //search
        moduleName: "",
        //css
        tableHeight: 0,
        treeHeight: 0,
        //otherparams
        ParentModuleCode: 'Top',
        ParentModuleGuid: 'Top',
        SearchInAll: false
    };
    new Vue({
        el: '#app',
        data: pageData,
        mounted: function () {
            bindTree();
            pageData.tableHeight = CaculateTableHeight();
            pageData.treeHeight = CaculatWindowHeight();
        },
        methods: {
            pageIndexChange:function(val){
                this.pageIndex = val
            },
            bindGrid: function () {
                bindGrid();
            },
            add: function () {
                OpenTopDialog('moduleadd', '添加模块', 'Frame/Module/Add?ParentModuleGuid=' + pageData
                    .ParentModuleGuid, 600, 800, bindGrid)
            },
            edit: function (index, row) {
                OpenTopDialog('moduleedit', '编辑模块', 'Frame/Module/Edit?RowGuid=' + row.RowGuid, 600, 800,
                    bindGrid)
            },
            batchDelete: function () {
                var selectRow = this.$refs.table.getSelectRow();
                if (selectRow.length == 0) {
                    OpenWaring('提示', '请选择删除的数据')
                } else {
                    OpenConfirm('提示', '确认删除选中的数据？', function () {
                        var KeyGuidList = "";
                        selectRow.forEach(element => {
                            KeyGuidList += element.RowGuid + ";";
                        });
                        var data = {
                            KeyGuidList: KeyGuidList
                        }
                        JsonAjaxPost(batchDeletetUrl, JSON.stringify(data), function (data,
                            status) {
                            if (data.code == 0) {
                                OpenSuccess('提示', '删除成功！', bindGrid)
                            } else {
                                OpenFail('提示', data.msg)
                            }
                        })
                    })
                }
            },
            nodeClick: function (data, checked, node) {
                pageData.ParentModuleCode = data.arttibutes.modulecode
                pageData.ParentModuleGuid = data.id
                bindGrid();
            }
        }
    })

    function bindGrid() {
        var data = {
            PageIndex: pageData.pageIndex,
            PageSize: pageData.pageSize,
            ModuleName: pageData.moduleName,
            ParentModuleCode: pageData.ParentModuleCode,
            SearchInAll: pageData.SearchInAll
        }
        JsonAjaxPost(tableUrl, JSON.stringify(data), function (data, status) {
            Vue.set(pageData, "tableData", data.data);
            Vue.set(pageData, "total", data.total)
        })
    }

    function bindTree() {
        var data = {

        }
        JsonAjaxPost(treeUrl, JSON.stringify(data), function (data, status) {
            Vue.set(pageData, "treeData", data.tree);
        })
    }
</script>